<template>
  <div>
    <Footer />

    <div class="top">
      <div class="box2">
        <form action="/">
          <van-search
            v-model="value"
            placeholder="请输入搜索关键词"
            @search="onSearch"
          />
        </form>
      </div>
    </div>
    <div class="content">
      <div class="left">
        <div
          class="in-box1"
          v-for="(item, index) in list"
          :key="index"
          @click="show(index)"
        >
          <span>{{ item.name }}</span>
        </div>
      </div>
      <div class="right" id="rightText">
        <div class="box" v-for="(item, index) in rightList" :key="index">
          <img :src="item.imgUrl" alt="" />
          <p>{{ item.masterName }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import $axios from "../../api/request";
import Footer from "../../components/Footer.vue";
export default {
  components: {
    Footer,
  },
  data() {
    return {
      list: [],
      rightList: [],
      showList: [],
      value: "",
      index: this.$route.params.id,
    };
  },
  created() {
    this.getList();
    this.shoppingList();
  },
  methods: {
    //左边分类渲染
    getList() {
      $axios.get("http://zl.huruqing.cn:3003/category/all").then((res) => {
        this.list = res.list;
      });
    },
    //右边商品渲染
    shoppingList() {
      $axios.get("http://zl.huruqing.cn:3003/category/all").then((res) => {
        this.showList = res.list[this.index].categoryId;
        $axios
          .get(
            "http://zl.huruqing.cn:3003/product/list?categoryId=" +
              this.showList +
              "&&currPage=1"
          )
          .then((res) => {
            this.rightList = res.list;
          });
      });
    },
    //点击左边渲染页面
    show(index) {
      $axios.get("http://zl.huruqing.cn:3003/category/all").then((res) => {
        this.showList = res.list[index].categoryId;
        $axios
          .get(
            "http://zl.huruqing.cn:3003/product/list?categoryId=" +
              this.showList +
              "&&currPage=1"
          )
          .then((res) => {
            this.rightList = res.list;
          });
      });
    },
    //搜索框
    onSearch() {
      $axios
        .get("http://zl.huruqing.cn:3003/product/search?keyword=" + this.value)
        .then((res) => {
          this.rightList = res.list;
        });
    },
  
  },
};
</script>

<style lang="scss" scoped>
@import "./type.scss";
body{
  background-color: red;
}
</style>